<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Title</title>
  </head>
  <body>
  
  </body>
  
  <script>
    let promise1 = new Promise((resolve, reject) => {
      console.log('promise');
      resolve('success');
    });
    console.log(promise1);// Promise {<fulfilled>: 'success'}
    
    let promise2 = new Promise((resolve, reject) => {
      console.log('promise');
      reject('fail');// 后续无then第二参数或catch进行错误处理则异常将在控制台输出
    });
    console.log(promise2);// Promise {<rejected>: 'fail'}
    
    let promise3 = new Promise((resolve, reject) => {
      if (Math.round(Math.random() * 10) > 5) {
        console.log('promise success');
        resolve(new Promise(() => {}));
      } else {
        console.log('promise fail');
        reject(new Promise(() => {}));
      }
    }).then(() => {
      console.log(promise3);
      console.log('success');
    }, () => {
      console.log(promise3);
      console.log('fail');
    });
    // 输出结果
    // promise success
    // promise fail - Promise {<pending>} - fail
    
    let promise4 = new Promise((resolve, reject) => {
      if (Math.round(Math.random() * 10) > 5) {
        console.log('promise success');
        resolve(new Promise((resolve, reject) => {reject('参数fail');}));
      } else {
        console.log('promise fail');
        reject(new Promise((resolve, reject) => {resolve('参数success');}));
      }
    }).then((res) => {
      console.log(promise4);
      console.log('success', res);
    }, (res) => {
      console.log(promise4);
      console.log('fail', res);
    });
    // 输出结果
    // promise success - Promise {<pending>} - fail 参数fail
    // promise fail - Promise {<pending>} - fail Promise {<fulfilled>: '参数success'}
  </script>
</html>